<?php
require_once($server->my_site[0]->path.$server->my_site[0]->folder."distributor_manage.php");

$distributor->id or exit("Área reservada a distribuidores");

$customer = new user();

// First we search for if the order is in the distributor arrays
$myorder=null;
foreach ($distributor->unprocessed_orders as $order) {
	if ($order->id==$_GET['order_id']) {
		$myorder=$order;
		break;
	}
}
if (!$myorder) {
	foreach ($distributor->processed_orders as $order) {
		if ($order->id==$_GET['order_id']) {
			$myorder=$order;
			break;
		}
	}
}
$customer->id=$order->user_id;
$customer->order=$order;
$customer->db_load();
?>

	<table style="width:100%;">
		<tr>
			<td style="padding:10px;">
				<div style="background-color:#A9E8FF;padding:5px;">Pago por <?php print $customer->order->payment->method->name; ?></div>
				<table id="order" style="margin-top:10px">
				<tbody>
					<tr> 
						  <th style="width:60px">Cantidad </th>
						  <th>Producto </th>
						  <th style="width:80px;text-align: right;">Precio </th>
						  <th style="width:80px;text-align: right;">Total </th>
					</tr>
<?php
	foreach($customer->order->items as $item) {
?>
	<tr class="product">
		<td>
			<?php print $item->name; ?>
		</td>
		<td class="quantity" style="text-align:center">
			<?php echo $item->quantity; ?>
		</td>
		<td class="price" style="text-align:right"><?php echo number_format($item->price, 2, ',', ' '); ?> €</td>
		<td class="total" style="text-align:right"><?php echo number_format($item->price * $item->quantity, 2, ',', ' '); ?> €</td>
	</tr>
<?php
	}
?>
        <tr> 
		<td colspan="4" class="hr"></td>
        </tr>
	<tr class="total">
		<td colspan="3">Subtotal:</td>
		<td style="text-align:right"><?php print number_format($customer->order->subTotal, 2, ',', ' '); ?> €</td>
	<tr class="total">
		<td colspan="3">Gastos de cobro:</td>
		<td style="text-align:right"><?php print number_format($customer->order->payment->method->price, 2, ',', ' '); ?> €</td>
	</tr>
	<tr class="total">
		<td colspan="3">Gastos de envio:</td>
		<td style="text-align:right"><?php print number_format($customer->order->delivery->shipping_type->price, 2, ',', ' '); ?> €</td>
	</tr>
	<tr class="total">
		<td colspan="3">Total:</td>
		<td style="text-align:right"><?php print number_format($customer->order->price, 2, ',', ' '); ?> €</td>
	</tr>
					</tbody>
				</table>
			</td>
			<td style="width:500px;padding:0 15px;">
				<div style="background-color:#ecfaff;padding:5px">
					<table style="width:100%">
					  <tbody>
					  <tr>
					    <td><?php print $customer->order->delivery->address->firstname . " " . $customer->order->delivery->address->lastname; ?></td>
					  </tr>
					  <tr>
					    <td><?php print $customer->order->delivery->address->street; ?></td>
					  </tr>
					  <tr>
					    <td><?php print $customer->order->delivery->address->postcode . ' ' . $customer->order->delivery->address->city; ?></td>
					  </tr>
					  <tr>
					    <td>Tlfs: <?php print $customer->order->delivery->phone; ?></td>
					  </tr>
					  <tr>
					    <td><a href="mailto:<?php print $customer->email; ?>"><?php print $customer->email; ?></a></td>
					  </tr>
					  <tr>
					    <td>Num <?php echo $customer->order->id; ?>. <?php echo $customer->id; ?>.</td>
					  </tr>
					  </tbody>
					</table>
				</div>
				<div style="padding:5px;background-color:#ecfaff">
					<?php print "Fecha: " . $customer->order->status_date; ?>
				</div>
				<div style="padding:5px;background-color:#A9E8FF">Envío por <?php print $customer->order->delivery->shipping_type->name; ?></div>
				<div style="padding:5px;">
					<form action="?section=order_save_comments" method="post" enctype="application/x-www-form-urlencoded;charset=UTF-8" myFor="#results">
					<textarea name="comments" style="width:390px" rows="2"><?php echo $customer->order->comments;?></textarea>
					<input type ="hidden" name="order_id" value="<?php echo $customer->order->id;?>">
					<input type="submit" value="Guardar">
					</form>
				</div>
				<table>
					<tr>
					<td class="order_menu">
					<?php if ($customer->order->status=='1') { ?>
						<table  class="button"><tr><td><a href="?section=order_process&order_id=<?php print $customer->order->id; ?>" myFor="#results">Process</a></td></tr></table>
					<?php } else if ($customer->order->status >=2) { ?>
						<table  class="button"><tr><td><a href="?section=order_undoprocess&order_id=<?php print $customer->order->id; ?>" myFor="#results">Undo Process</a></td></tr></table>
					<?php } ?>
						<table  class="button"><tr><td><a href="?section=order_print&order_id=<?php print $customer->order->id; ?>" myFor="#results">Print</a></td></tr></table>
						<table  class="button"><tr><td><a href="?section=order_delete&order_id=<?php print $customer->order->id; ?>" myFor="#results">Delete</a></td></tr></table>
					</td>
					</tr>
				</table>
			</td>
		</tr>	
	</table>